Skip to content

GROOVY-11968: SC: trait static field access generates invalid bytecod…#2495

Merged
paulk-asert merged 1 commit intoapache:masterfrom
paulk-asert:groovy11968
May 1, 2026
Merged

GROOVY-11968: SC: trait static field access generates invalid bytecod…#2495
paulk-asert merged 1 commit intoapache:masterfrom
paulk-asert:groovy11968

Conversation

@paulk-asert
Copy link
Copy Markdown
Contributor

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes GROOVY-11968 (follow-up to GROOVY-11907) where statically compiled trait static-field access could route sub-expressions through the regular (non-static) call-site writer, producing invalid bytecode under indy=false.

Changes:

  • Track whether the current statically compiled method contains any DYNAMIC_RESOLUTION sub-expressions (via an AST scan).
  • Ensure the regular CallSiteWriter per-method prologue is emitted at method entry when such dynamic-resolution sub-expressions exist.
  • Add a regression test that compiles and runs the reproducer script with indy=true and indy=false.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/test/groovy/org/codehaus/groovy/transform/traitx/Groovy11968.groovy New regression test covering helper verification under both indy modes
src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesWriterController.java Detects presence of DYNAMIC_RESOLUTION within statically compiled methods/ctors
src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesCallSiteWriter.java Emits regular call-site writer method prologue when needed to avoid invalid locals

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 27, 2026

Codecov Report

❌ Patch coverage is 82.75862% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 67.1794%. Comparing base (839717c) to head (e98ad40).
⚠️ Report is 10 commits behind head on master.

Files with missing lines Patch % Lines
...y/classgen/asm/sc/StaticTypesWriterController.java 81.4815% 0 Missing and 5 partials ⚠️
Additional details and impacted files

Impacted file tree graph

@@                Coverage Diff                 @@
##               master      #2495        +/-   ##
==================================================
+ Coverage     67.0917%   67.1794%   +0.0878%     
- Complexity      31765      31852        +87     
==================================================
  Files            1465       1465                
  Lines          123373     123511       +138     
  Branches        22107      22138        +31     
==================================================
+ Hits            82773      82974       +201     
+ Misses          33493      33400        -93     
- Partials         7107       7137        +30     
Files with missing lines Coverage Δ
...ovy/classgen/asm/sc/StaticTypesCallSiteWriter.java 78.7946% <100.0000%> (+0.5435%) ⬆️
...y/classgen/asm/sc/StaticTypesWriterController.java 91.5663% <81.4815%> (-4.8623%) ⬇️

... and 23 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@paulk-asert paulk-asert merged commit 84f2f37 into apache:master May 1, 2026
24 checks passed
@paulk-asert paulk-asert deleted the groovy11968 branch May 1, 2026 03:40
jamesfredley pushed a commit to apache/grails-core that referenced this pull request May 2, 2026
Re-audited every Groovy 6 workaround in this canary against the latest
Apache Groovy master. Three fixes have merged and are present in the
6.0.0-SNAPSHOT artifact (latest publication: 2026-05-02 11:47:43 UTC,
build #546), so the corresponding workarounds can be removed.

GROOVY-11968 (apache/groovy#2495), merged 2026-05-01 03:40 UTC,
SHA 84f2f37c4f93d6ea44ad8bc76570704c84499c6b
  - grails-geb/.../ContainerSupport.groovy: revert @CompileDynamic to
    @CompileStatic now that the trait-static-field VerifyError under
    indy=false no longer triggers.

GROOVY-11967 (apache/groovy#2493), merged 2026-05-01 09:37 UTC,
SHA 406feaf5082f1741c318f924b520c4c27bfa0754
  - DefaultConstraintFactory.groovy: collapse the two explicit
    constructors back to a single constructor with a default-valued
    List parameter; the @CompileStatic VerifyError on the synthesised
    bridge constructor no longer reproduces.
  - MappingContextAwareConstraintFactory.groovy: same collapse.

GROOVY-11966 (apache/groovy#2492), merged 2026-05-01 18:58 UTC,
SHA 8dde1c84134ef6fdeecf26b5cbb5183d5aab4dac
  - GroovyPageCompiler.groovy: drop the parallelism guard and the
    grails.gsp.compiler.parallelism system property; restore the
    original Executors.newFixedThreadPool(availableProcessors() * 2)
    sizing now that AnnotationNode.isTargetAllowed -> ListHashMap is
    thread-safe again.
  - AbstractGroovyTemplateCompiler.groovy: same restoration; drop the
    grails.views.compiler.parallelism system property.

Verified locally on Java 21 / Groovy 6.0.0-SNAPSHOT build #546:
  ./gradlew :grails-datamapping-validation:compileGroovy
  ./gradlew :grails-datamapping-core:compileGroovy
  ./gradlew :grails-gsp-core:compileGroovy
  ./gradlew :grails-views-core:compileGroovy
  ./gradlew :grails-geb:compileTestFixturesGroovy
  -> all BUILD SUCCESSFUL

The remaining workarounds (TraitReceiverTransformer static-method
override loss, MetaClassImpl genericGetMethod hijack on GORM entities,
@CompileStatic named-argument render(Map) silent no-op, smart-cast
in 'if (cond && !(x instanceof Y))', VariableScopeVisitor NPE, and
ConfigObject [] mutation) have no upstream fix yet and stay in place.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants